package sketchpad.gui.drawinggraph;

import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import sketchpad.constant.CHNName;
import sketchpad.constant.Geometry;
import sketchpad.constant.SketchPadColor;
import sketchpad.gui.drawinggraph.node.Node;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

public class Random extends DrawItem implements Serializable {

    private List<Node> nodeList;

    public Random(int id, Node node){
        super(id, node);
        setGeometryClass(Geometry.RANDOM);
        nodeList = new LinkedList<>();
        nodeList.add(node);
        setLabel(CHNName.RANDOM);
    }

    public List<Node> getNodeList() {
        return nodeList;
    }

    public void setNodeList(List<Node> nodeList) {
        this.nodeList = nodeList;
    }

    @Override
    public void draw(Node mouseNode, GraphicsContext gc){
        int idx = 1;
        int size = getNodeList().size();
        double x8 = getNodeList().get(0).x;
        double y8 = getNodeList().get(0).y;
        double x7;
        double y7;
        if (!isSelect())gc.setStroke(Color.valueOf(SketchPadColor.COLOR_RANDOM));
        while(idx<size){
            x7 = getNodeList().get(idx).x;
            y7 = getNodeList().get(idx).y;
            gc.strokeLine(x7,y7,x8,y8);
            x8 = x7;
            y8 = y7;
            idx++;
        }
    }
}
